package com.ljh.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ljh.pojo.Dinding;
import com.ljh.pojo.Floors;
import com.ljh.pojo.Reservation;
import com.ljh.service.DINDINGervice;
import com.ljh.service.FLOORService;
import com.ljh.service.RESERVATIONervice;
import com.ljh.service.USERervice;
import com.ljh.vo.Dindingshow;
import com.ljh.vo.LoginVo;
import com.ljh.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘剑鸿
 * @since 2021-09-08
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private USERervice useRervice;
    @Autowired
    private DINDINGervice dindinGervice;
    @Autowired
    private FLOORService floorService;

    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/index")
    public String toindex(Model model){

        List<Dinding> dindingList =dindinGervice.getAll();
        List<Dinding> getAlltwo = dindinGervice.getAlltwo();
        List<Dinding> getAllthree = dindinGervice.getAllthree();
        List<Floors> foolrs = floorService.getfloors();
        model.addAttribute("din",dindingList);
        model.addAttribute("din2",getAlltwo);
        model.addAttribute("din3",getAllthree);
        Dindingshow<Dinding> dinname =dindinGervice.getdiningstate();

       // List<Reservation> res = reservatioNervice.selectres();
        model.addAttribute("dinn",dinname);
        model.addAttribute("foolr",foolrs);
//        model.addAttribute("res",res);
//        System.out.println("预约"+res);
        return "fronydesk/index";
    }
    @RequestMapping("doLogin")
    @ResponseBody
    public RespBean doLogin(HttpSession session, LoginVo loginVo){
        session.setAttribute("loginUser",loginVo.getMobile());
        return useRervice.doLogin(session,loginVo);
    }

    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:login.html";
    }


}

